#include "rectangletool.h"
#include "itemsmanager.h"

#include <QMessageBox>
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPen>
#include <QBrush>
#include <QDebug>

void RectangleTool::mouseReleased(QGraphicsSceneMouseEvent *e)
{
    PaintTool::mouseReleased(e);
    ItemsManager::instance()->setCurrentItem(NULL);
}

void RectangleTool::mousePressed(QGraphicsSceneMouseEvent *e)
{
    PaintTool::mousePressed(e);
    QGraphicsRectItem* r = ((QGraphicsScene*)ItemsManager::instance()->paintScene())->
                           addRect(downX, downY, 0, 0, QPen(QColor(0,0,0)), Qt::SolidPattern);
    QGraphicsScene *scene = ((QGraphicsScene*)ItemsManager::instance()->paintScene());

    ItemsManager::instance()->setCurrentItem(r);
}

void RectangleTool::mouseMoved(QGraphicsSceneMouseEvent *e)
{
    PaintTool::mouseMoved(e);
    if(this->mouseDown)
    {
        QGraphicsRectItem *r = (QGraphicsRectItem*) ItemsManager::instance()->currentItem();
        r->setRect(downX, downY, curX - downX, curY - downY);
    }
}
